package com.ruoyi.project.poem.poemuser.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.poem.poemuser.domain.PoemUser;
import com.ruoyi.project.poem.poemuser.mapper.PoemUserMapper;
import com.ruoyi.project.poem.poemuser.service.IPoemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 诗词用户Service业务层处理
 *
 * @author shixiangwen
 * @date 2022-10-11
 */
@Service
@DataSource(DataSourceType.POEMBBS)
public class PoemUserServiceImpl implements IPoemUserService {
    @Autowired
    private PoemUserMapper poemUserMapper;

    /**
     * 查询诗词用户
     *
     * @param id 诗词用户ID
     * @return 诗词用户
     */
    @Override
    public PoemUser selectPoemUserById(Long id) {
        return poemUserMapper.selectPoemUserById(id);
    }

    /**
     * 查询诗词用户列表
     *
     * @param poemUser 诗词用户
     * @return 诗词用户
     */
    @Override
    public List<PoemUser> selectPoemUserList(PoemUser poemUser) {
        return poemUserMapper.selectPoemUserList(poemUser);
    }

    @Override
    public PoemUser selectPoemUserOne(String userId) {
        PoemUser poemUser = new PoemUser();
        poemUser.setUserId(userId);
        List<PoemUser> poemUsers = poemUserMapper.selectPoemUserList(poemUser);
        if (!poemUsers.isEmpty()) {
            return poemUsers.get(0);
        }
        return null;
    }

    /**
     * 新增诗词用户
     *
     * @param poemUser 诗词用户
     * @return 结果
     */
    @Override
    public int insertPoemUser(PoemUser poemUser) {
        return poemUserMapper.insertPoemUser(poemUser);
    }

    /**
     * 修改诗词用户
     *
     * @param poemUser 诗词用户
     * @return 结果
     */
    @Override
    public int updatePoemUser(PoemUser poemUser) {
        return poemUserMapper.updatePoemUser(poemUser);
    }

    /**
     * 删除诗词用户对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePoemUserByIds(String ids) {
        return poemUserMapper.deletePoemUserByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除诗词用户信息
     *
     * @param id 诗词用户ID
     * @return 结果
     */
    @Override
    public int deletePoemUserById(Long id) {
        return poemUserMapper.deletePoemUserById(id);
    }
}
